//
//  UserDTO.m
//  QuickCure
//
//  Created by 马文星 on 16/5/2.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "UserDTO.h"

#define kTrue_name @"true_name"
#define kUser_id  @"user_id"
#define kCard_number  @"card_number"

@implementation UserDTO


/*
 注意：
    咱们上课，老师教我们大家用归档，其实是很好的，下面也给大家介绍一个使用偏好设置，
    这个也是工作中常用，大家都要掌握以下
 
 */


//单例
+(instancetype)sharedInstance{
    
    static UserDTO *instance = nil;
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        //1.
        instance = [[UserDTO alloc] init];
        
    });
    return instance;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}



-(void)saveUserInfoToSanbox:(UserDTO *)dto{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    [defaults setObject:dto.user_id forKey:kUser_id];
    [defaults setObject:dto.true_name forKey:kTrue_name];
    [defaults setObject:dto.card_number forKey:kCard_number];
    
    [defaults synchronize];
}

-(void)loadUserInfoFromSanbox{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    self.user_id         = [defaults objectForKey:kUser_id];
    self.true_name       = [defaults objectForKey:kTrue_name];
    self.card_number     = [defaults objectForKey:kCard_number];
    
}

///退出登录后 清楚数据
-(void)clearUserData{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:kUser_id];
    [defaults removeObjectForKey:kTrue_name];
    [defaults removeObjectForKey:kCard_number];

    self.user_id = @"";
    self.true_name = @"";
    self.card_number = @"";
}


@end
